package medium;
/*
405. 数字转换为十六进制数
 */
public class LeeCode405 {

  public static void main(String[] args) {
    System.out.println(new LeeCode405().toHex(1000000000));
  }

  public String toHex(int num){
    if (num == 0){
      return "0";
    }
    StringBuffer buffer = new StringBuffer();
    for (int i = 7; i >= 0 ; i--) {
      int val = (num >> (4 * i)) & 0xf;
      if (buffer.length() > 0 || val > 0){
        char digt = val < 10 ? (char)('0' + val) : (char)('a' + val - 10);
        buffer.append(digt);
      }
    }
    return buffer.toString();
  }
}
